<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="演员" prop="actorId">
        <el-select v-model="queryParams.actorId" clearable filterable placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.actorId"
            :label="item.actorName"
            :value="item.actorId">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="性别" prop="actorMessageSex">
        <el-select v-model="queryParams.actorMessageSex" placeholder="请选择性别" clearable size="small">
          <el-option label="请选择性别" value="" />
         <el-option label="男" value="男" />
                               <el-option label="女" value="女" />
                               <el-option label="人妖" value="人妖" />

        </el-select>
      </el-form-item>
      <el-form-item label="生日" prop="actorMessageBirth">
        <el-date-picker clearable size="small"
          v-model="queryParams.actorMessageBirth"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择生日">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['xqsp:message:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['xqsp:message:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="messageList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="spActorMessage.actorMessageId" />
       <el-table-column label="演员" align="center" prop="actorName" />
      <el-table-column label="感情状态" align="center" prop="spActorMessage.actorMessageEmotionalState" />
      <el-table-column label="喜欢" align="center" prop="spActorMessage.actorMessageLove" />
      <el-table-column label="性别" align="center" prop="spActorMessage.actorMessageSex" />
      <el-table-column label="生日" align="center" prop="spActorMessage.actorMessageBirth" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.spActorMessage.actorMessageBirth, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="spActorMessage.actorMessageAge" />
      <el-table-column label="种族" align="center" prop="spActorMessage.actorMessageRace" />
      <el-table-column label="发色" align="center" prop="spActorMessage.actorMessageHairColor" />
      <el-table-column label="假奶子" align="center" prop="spActorMessage.actorMessageFakeMilk" />
      <el-table-column label="三围" align="center" prop="spActorMessage.actorMessageSanwei" />
      <el-table-column label="身高(cm)" align="center" prop="spActorMessage.actorMessageStature" />
      <el-table-column label="体重(kg)" align="center" prop="spActorMessage.actorMessageWeight" />
      <el-table-column label="城市和国家" align="center" prop="spActorMessage.actorMessageSite" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['xqsp:message:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['xqsp:message:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改演员信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="感情状态" prop="actorMessageEmotionalState">
          <el-input v-model="form.actorMessageEmotionalState" placeholder="请输入感情状态" />
        </el-form-item>
        <el-form-item label="喜欢" prop="actorMessageLove">
          <el-input v-model="form.actorMessageLove" placeholder="请输入喜欢" />
        </el-form-item>
        <el-form-item label="性别" prop="actorMessageSex">
          <el-select v-model="form.actorMessageSex" placeholder="请选择性别">
            <el-option label="请选择性别" value="" />
            <el-option label="男" value="男" />
                      <el-option label="女" value="女" />
                      <el-option label="人妖" value="人妖" />
          </el-select>
        </el-form-item>
        <el-form-item label="生日" prop="actorMessageBirth">
          <el-date-picker clearable size="small"
            v-model="form.actorMessageBirth"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择生日">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="年龄" prop="actorMessageAge">
          <el-input v-model="form.actorMessageAge" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="种族" prop="actorMessageRace">
          <el-input v-model="form.actorMessageRace" placeholder="请输入种族" />
        </el-form-item>
        <el-form-item label="发色" prop="actorMessageHairColor">
          <el-input v-model="form.actorMessageHairColor" placeholder="请输入发色" />
        </el-form-item>
        <el-form-item label="假奶子" prop="actorMessageFakeMilk">
          <el-input v-model="form.actorMessageFakeMilk" placeholder="请输入假奶子" />
        </el-form-item>
        <el-form-item label="三围" prop="actorMessageSanwei">
          <el-input v-model="form.actorMessageSanwei" placeholder="请输入三围" />
        </el-form-item>
        <el-form-item label="身高(cm)" prop="actorMessageStature">
          <el-input v-model="form.actorMessageStature" placeholder="请输入身高" />
        </el-form-item>
        <el-form-item label="体重(kg)" prop="actorMessageWeight">
          <el-input v-model="form.actorMessageWeight" placeholder="请输入体重" />
        </el-form-item>
        <el-form-item label="城市和国家" prop="actorMessageSite">
          <el-input v-model="form.actorMessageSite" placeholder="请输入城市和国家" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMessage, getMessage, delMessage, addMessage, updateMessage, exportMessage } from "@/api/xqsp/message";
import { listActor } from "@/api/xqsp/actor";
export default {
  name: "Message",
  components: {
  },
  data() {
    return {
      //演员下拉框
      options:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 演员信息表格数据
      messageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      Name:"",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        actorId: null,
        actorMessageEmotionalState: null,
        actorMessageLove: null,
        actorMessageSex: null,
        actorMessageBirth: null,
        actorMessageAge: null,
        actorMessageRace: null,
        actorMessageHairColor: null,
        actorMessageFakeMilk: null,
        actorMessageSanwei: null,
        actorMessageStature: null,
        actorMessageWeight: null,
        actorMessageSite: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        actorMessageAge:[
          {
            pattern: /^120$|^[ 1 - 9 ]$|^((1[0-1])|[1-9])\d$/,
            message: '请输入规范的年龄信息',
            trigger: 'blur'
          }
        ],
        actorMessageWeight:[
          {
            pattern:  /^([0-9]{2,3})$/,
            message: '请输入规范的体重信息',
            trigger: 'blur'
          }
        ],
        actorMessageStature:[
          {
            pattern: /^([0-9]{3})$/,
            message: '请输入规范的身高信息',
            trigger: 'blur'
          }
        ],

      }
    };
  },
  created() {
    this.getList();
    this.getActorList();
  },
  methods: {

    //查询演员
    getActorList() {
      listActor(this.queryParams).then(response => {
        this.options = response.rows;
      });
    },

    /** 查询演员信息列表 */
    getList() {
      this.loading = true;
      listMessage(this.queryParams).then(response => {
        this.Name=response.rows.actorName;
        this.messageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        actorMessageId: null,
        actorId: null,
        actorMessageEmotionalState: null,
        actorMessageLove: null,
        actorMessageSex: null,
        actorMessageBirth: null,
        actorMessageAge: null,
        actorMessageRace: null,
        actorMessageHairColor: null,
        actorMessageFakeMilk: null,
        actorMessageSanwei: null,
        actorMessageStature: null,
        actorMessageWeight: null,
        actorMessageSite: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.spActorMessage.actorMessageId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加演员信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();

      const actorMessageId = row.spActorMessage.actorMessageId || this.ids
      getMessage(actorMessageId).then(response => {
        this.form = response.data;

        this.open = true;
        this.title = "修改演员“"+ row.actorName+"”信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.actorMessageId != null) {
            updateMessage(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMessage(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      let tmpIds=[]
      if (this.ids.length>0){
        for (const id of this.ids) {
          tmpIds.push(id);
        }
      }else {
        tmpIds.push(row.spActorMessage.actorMessageId);
      }
      this.$confirm('是否确认删除演员信息编号为"' +tmpIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delMessage(tmpIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })


    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有演员信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportMessage(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
